package photobox.utils

/**
 * Created by x on 6/20/14.
 */
class HQLUtils {

    static def whereCondition(name, opt, key) {
        if (opt == 'eq') {
            opt = '='
        } else if (opt == 'ne') {
            opt = '<>'
        } else if (opt == 'lt') {
            opt = '<'
        } else if (opt == 'le') {
            opt = '<='
        } else if (opt == 'gt') {
            opt = '>'
        } else if (opt == 'ge') {
            opt = '>='
        } else if (opt == 'cn') {
            opt = 'like'
            key = "%${key}%"
        } else {
            throw RuntimeException("不能识别的操作符: ${opt}")
        }
        return "${name} ${opt} :${key}"
    }

}
